<div id="tb<?php echo $uniqid;?>" style="padding:5px">
	<table cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
			<td><a href="javascript:void(0);" onclick="MerchantStoreAdd();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span class="l-btn-text">增加</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="MerchantStoreEdit();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="MerchantStoreDrop();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="MerchantStoreReload();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
			<td>&nbsp;&nbsp;<input id="MerchantStoreKeywords" style="width:200px" type="text" placeholder="请输入门店的ID或名称"
								  class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" onclick="MerchantStoreSearch();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
		</tr>
		</tbody>
	</table>
</div>
<div class="con"  style="-moz-user-select:none;">
	<table id="MerchantStoreTable"></table>
</div>
<div id="MerchantStoredlg" class="easyui-dialog" style="width:720px; height:520px;" title="信息框" closed="true"></div>
<script>
	var MerchantStoreAdd = function () {
		$("#MerchantStoredlg").dialog({
			title: '新增信息',
			closed: false,
			width: 740,
			height: 520,
			cache: false,
			href: '/merchant/store/add',
			modal: true,
			buttons: [{
				text: '保存',
				id: 'MerchantStoreSubmit',
				iconCls: 'icon-ok',
			}, {
				text: '关闭',
				iconCls: 'icon-no',
				handler: function () {
					$("#MerchantStoredlg").dialog('close');
				}
			}]
		});
	};
	var MerchantStoreEdit = function (opt_id) {
		let rowId = opt_id || ($('#MerchantStoreTable').datagrid('getSelected') && $('#MerchantStoreTable').datagrid('getSelected').id);
		if (rowId) {
			$("#MerchantStoredlg").dialog({
				title: '编辑信息',
				closed: false,
				width: 740,
				height: 520,
				cache: false,
				href: '/merchant/store/edit?id=' + rowId,
				modal: true,
				buttons: [{
					text: '保存',
					id: 'MerchantStoreSubmit',
					iconCls: 'icon-ok',
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$("#MerchantStoredlg").dialog('close');
					}
				}]
			});
		} else {
			$.messager.alert('提示', '请先选择要编辑的行！', 'warning');
		}
	};
	var MerchantStoreToggleStatus = function (opt_id) {
		let rowId = opt_id;
		if (rowId) {
			$.messager.confirm('提示', '确定切换门店状态吗？', function (r) {
				if (r) {
					$.messager.progress();
					$.post('/merchant/store/togglestatus', {id: rowId}, function (data) {
						$.messager.progress('close');
						if (data.ret === 0) {
							$.messager.show({
								title: '提示',
								msg: data.msg,
								timeout: 3000,
								showType: 'slide'
							});
							MerchantStoreReload();
						} else {
							$.messager.alert('提示', data.msg, 'warning');
						}
					}, 'json');
				}
			});
		} else {
			$.messager.alert('提示', '请先选择要删除的行！', 'warning');
		}
	};
	var MerchantStoreDrop = function (opt_id) {
		let rowId = opt_id || ($('#MerchantStoreTable').datagrid('getSelected') && $('#MerchantStoreTable').datagrid('getSelected').id);
		if (rowId) {
			$.messager.confirm('提示', '确定删除吗？', function (r) {
				if (r) {
					$.messager.progress();
					$.post('/merchant/store/drop', {id: rowId}, function (data) {
						$.messager.progress('close');
						if (data.ret === 0) {
							$.messager.show({
								title: '提示',
								msg: data.msg,
								timeout: 3000,
								showType: 'slide'
							});
							MerchantStoreReload();
						} else {
							$.messager.alert('提示', data.msg, 'warning');
						}
					}, 'json');
				}
			});
		} else {
			$.messager.alert('提示', '请先选择要删除的行！', 'warning');
		}
	};
	var MerchantStoreReload = function () {
		$("#MerchantStoreTable").datagrid('reload');
	};
	var MerchantStoreSearch = function () {
		var height = $(window).height() - $(".top").height() - 46;
		var width = $(window).width() - $(".leftmenu").width() - 8;
		$("#MerchantStoreTable").datagrid({
			title: '门店列表',
			width: width,
			height: height,//高度
			singleSelect: true,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: false,//如果为true，则显示一个行号列。
			pagination: true,//是否显示分页
			pageSize: 10,
			pageList: [10, 15, 20, 25],
			method: 'post',
			sortName: 'id',
			sortOrder: 'desc',
			idField: 'id',
			treeField: 'title',
			url: '/merchant/store/index',
			queryParams: {keywords: $('#MerchantStoreKeywords').val()},
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: false,
			checkOnSelect: true,
			toolbar: '#tb<?php echo $uniqid;?>',
			columns: [[
				{field:'id',title:'ID', align: 'center', halign: 'center',width:fixWidth(3)},
				{field:'name',title:'门店信息', align: 'left', halign: 'center',width:fixWidth(10),formatter(val, rowData, rowIndex){
						let info = '<div style="display: flex;align-items: center;">';
						if(rowData.images_arr.length > 1){
							info += '<img src="'+rowData.images_arr[0]+'" style="height:30px;width:30px;border-radius: 3px;border:1px solid #e6e6e6; margin-right: 3px;" />'
						}else{
							info += '<img src="'+rowData.images+'" style="height:30px;width:30px;border-radius: 3px;border:1px solid #e6e6e6; margin-right: 3px;" />'
						}
						info += '<p>'+val+'</p>'
						info += '</div>'
						return info;
					}},
				{field:'address',title:'门店地址', align: 'left', halign: 'center',width:fixWidth(10), styler: function(){
						return {class:'cell_white-space'};
					}, formatter(val, rowData, rowIndex)
					{
						if(val.indexOf(rowData.province_name) === 0) {
							return val;
						}else{
							return rowData.province_name + rowData.city_name + rowData.area_name + val;
						}
					}
				},
				{field:'realname',title:'联系人', align: 'center', halign: 'center',width:fixWidth(5)},
				{field:'phone',title:'电话', align: 'center', halign: 'center',width:fixWidth(5)},
				{field:'openhours',title:'营业时间', align: 'center', halign: 'center',width:fixWidth(5)},
				{field:'store_type',title:'配送方式', align: 'center', halign: 'center',width:fixWidth(5),formatter(val, rowData, rowIndex){
					let MerchantStore_type = '';
					if(parseInt(rowData.store)===1){
						MerchantStore_type += '<p style="color: #7438D5;">商家配送</p>';
					}
					if(parseInt(rowData.selfetch)===1){
						MerchantStore_type += '<p style="color: #0AB58F;">支持自提</p>';
					}
					return MerchantStore_type;
					}},
				{field:'status_text',title:'状态', align: 'center', halign: 'center',width:fixWidth(5),formatter:function (value,rowData,rowIndex){
						let text = rowData.status? value+'中':'已'+value;
						return '<span class="status_color_'+rowData.status+'">'+text+'</span>';
					}
				},
				{field: 'options', title: '操作', align: 'center', halign: 'center', width: fixWidth(8), formatter: function (value, rowData, rowIndex)
					{
						let buttons = '<div class="table">';
						buttons += '<span class="l-btn l-btn-small l-btn-left color9 table" onclick="MerchantStoreEdit(\'' + rowData.id + '\')"><span class="l-btn-text">编辑</span></span>';
						buttons += '<span class="l-btn l-btn-small l-btn-left color9 table" '+(rowData.status?'style="color:#d33632;"':'style="color:#0eb913;"')+' onclick="MerchantStoreToggleStatus(\'' + rowData.id + '\')"><span class="l-btn-text">'+(rowData.status?'禁用':'启用')+'</span></span>';
						buttons += '<span class="l-btn l-btn-small l-btn-left color9 table" onclick="MerchantStoreDrop(\'' + rowData.id + '\')"><span class="l-btn-text">删除</span></span>';

						return buttons + '</div>';
					}
				},
			]],
			onDblClickRow: function (index, field) {
				MerchantStoreEdit();
			}
		});
	};
	onDatagridResize("#MerchantStoreTable");
	MerchantStoreSearch();
</script>
<style>
	.l-btn-plain{
		border: rgba(0,0,0,0) 1px solid;
	}

	.datagrid-toolbar .selected {
		color: #f1f1f1;
		background: #1065a7;
		border: 1px solid #f0f0f0;
	}

	.cell_white-space > *{
		white-space: normal !important;
	}

	.keywords_input_search_box{
		width: 300px;
		border-color: #cccccc;
	}
	.status_color_1{
		color: #0eb913;
	}
	.status_color_0{
		color: #333333;
	}
</style>
